package me.kagami.myjvm;

import me.kagami.myjvm.jvm.MyJvm;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) throws IOException {
        ClassLoader classLoader = Main.class.getClassLoader();
        ClassNode classNode = loadInitialClass(classLoader.getResourceAsStream("me/kagami/myjvm/Add.class"));
        MethodNode addMethod = MyJvm.findPublicStaticMethod(classNode, "add");
        MyJvm.run(classNode, addMethod, new Integer(1), new Integer(2));
    }

    private static ClassNode loadInitialClass(InputStream is) throws IOException {
        ClassNode result = new ClassNode();
        ClassReader cr = new ClassReader(is);
        cr.accept(result, 0);
        return result;
    }

}